
#define DBG_TAG "MAIN"
#include "log.h"
#include "si4432.h"
#include "cmd_uart.h"
#include "bflb_wdg.h"
#include <FreeRTOS.h>
#include <queue.h>
#include <task.h>

struct bflb_device_s *wdg;

void wdg_task(void *arg)
{
    struct bflb_wdg_config_s wdg_cfg;
    wdg_cfg.clock_source = WDG_CLKSRC_32K;
    wdg_cfg.clock_div = 31;
    wdg_cfg.comp_val = 2000;
    wdg_cfg.mode = WDG_MODE_RESET;

    wdg = bflb_device_get_by_name("watchdog");
    bflb_wdg_init(wdg, &wdg_cfg);
    bflb_wdg_start(wdg);
    bflb_wdg_reset_countervalue(wdg);

    while (1) {
        bflb_mtimer_delay_ms(1000);
        if (get_ver() == 0x06) {
            bflb_wdg_reset_countervalue(wdg);
            printf("延迟. \r\n");
        } else {
            printf("SI4432没初始化成功. \r\n");
        }
        // value = bflb_wdg_get_countervalue(wdg);
        // printf("延迟. %d\r\n", value);
    }
}

int main(void)
{
    board_init();

    xTaskCreate(si4432_task, "si4432_task", 1024, NULL, 4, NULL);
    xTaskCreate(wdg_task, "wdg_task", 128, NULL, 3, NULL);
    xTaskCreate(cmd_uart_task, "cmd_uart_task", 1024, NULL, 3, NULL);
    vTaskStartScheduler();
}
